<script type="text/javascript">
$(function(){
	var pg = App.message.queueSearch.ui, pp = pg.params || {},
		gd = pg.find('.grid');
	
	var frm = {
		title: pg.seek('title'),
		key: pg.seek('key'),
		status: pg.seek('status'),
		date: [ pg.seek('startDate'), pg.seek('endDate') ],
		hour: [ pg.seek('startH'), pg.seek('endH') ],
		minute: [ pg.seek('startM'), pg.seek('endM') ],
		second: [ pg.seek('startS'), pg.seek('endS') ]
	}
	frm.title.text(pp.code);
	frm.status.mac('combo', {
		width: 118,
		data: Cache.message.status
	});
		
	gd.mac('grid', {
		key: 'id',
		cols: [{
			field: 'cId', title : '消息id', width: 300, 
			render: function(r){
				return r.message.id;
			}
		}, {
			field: 'addTime', title : '添加时间', width: 200,
			render: function(r){
				return new Date(r.addTime).format('yyyy-MM-dd HH:mm:ss.S');
			}
		}, {
			field: 'lastTime', title : '持续时间 ', width: 200,
			render: function(r){
				return new Date(r.lastTime).format('yyyy-MM-dd HH:mm:ss.S');
			}
		}, {
			field: 'status', title : '状态 ', width: 80,
			render: function(r, tr, me){
				return Cache.message.status[r.message.status];
			}
		},{
			field: 'tried', title : '尝试', width: 40,
		},{
			field: 'memo', title : '备注', width: 120,
		}],
		loader: {
			url: App.ctx + '/broker/msg.do',
			params: {
				pageNo: 1, pageSize: 50, target: pp.code
			},
			autoLoad: true
		},
	});
		
	pg.seek('back').click(function(){
		App.show({
			ctx: 'message',
			action: 'queueIndex',
			params: {}
		}, $.noop, pg.parent());
	});
	
	var dateCfg = {
		prevText: "<上一月",
		nextText: "下一月>",
		dateFormat: "yy-mm-dd",
		changeMonth: true,
		changeYear: true,
		inline: true
	};
	frm.date[0].datepicker(dateCfg); 
	frm.date[1].datepicker(dateCfg); 

	function adjust(){
		var h = pg.parent().height();
		pg.height(h);
		gd.parent().height(h - 100);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
	
	function getTime(i){
		var d = frm.date[i].val(), h = frm.hour[i].val() || 0,
			m = frm.minute[i].val() || 0, s = frm.second[i].val() || 0;
		if (!d) {
			return null;
		}
		h =  (h < 10? '0':'') + h;
		m =  (m < 10? '0':'') + m;
		s =  (s < 10? '0':'') + s;
		return d + ' ' + h + ':' + m + ':' + s;
	}
	
	function validate(){
		var s = frm.date[0].val(); 
		var e = frm.date[1].val();
		if (!s && !e) {
			return true;
		}
		return e > s;
	}
	pg.seek('ok').click(function(e) {
		console.log(getEndtTime());
		if (!validate()) { 
			mac.alert('结束时间应大于开始时间');
		} else {
			gd.load({
				target: pp.code,
				key: key.val(),
				status: status.val() == undefined? null: status.val(),
				startTime: getTime(0),
				endTime: getTime(1),
				addr: pp.addr
			});
		} 
	}); 
});

</script>
<div class="navi">
	<span class="a" name="back">队列与主题</span>&gt;&gt;
	<span name="title">Xxx队列</span>&gt;&gt;
	<span>数据查询</span>
</div>
<div class="top">
	<div class="item">
		<div class="label">关键字：</div>
		<input type="text" name="key" class="fl" placeholder="关键字" />
		<div class="label">状态：</div>
		<div class="combo fl" name="status" ></div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">时间范围：</div>
		<input class="long" name="startDate" />
		<span>&nbsp;</span>
		<input class="short" type="number" max="59" min="0" placeholder="时" name = "startH"/>
		<span>:</span>
		<input class="short" type="number" max="59" min="0" placeholder="分" name = "startM"/>
		<span>:</span>
		<input class="short" type="number" max="59" min="0" placeholder="秒" name = "startS"/>
		<span>&nbsp;到&nbsp;</span>
		<input class="long" name="endDate" />
		<span>&nbsp;</span>
		<input class="short" type="number" max="59" min="0" placeholder="时" name = "endH"/>
		<span>:</span>
		<input class="short" type="number" max="59" min="0" placeholder="分" name = "endM"/>
		<span>:</span>
		<input class="short" type="number" max="59" min="0" placeholder="秒" name = "endS"/>
		<button name="ok">统计</button>
		<div class="clear"></div>
	</div>
</div>
<div class="clear"></div>
<div class="body">
	<div class="grid"></div>
</div>